//
//  StatisticCoinView.swift
//  Crypto
//
//  Created by DaleGuo on 2023/9/23.
//

import SwiftUI

struct StatisticCoinView: View {
    let stat: StatisticModel

    var body: some View {
        VStack(alignment: .leading, spacing: 4) {
            Text(stat.title)
                .font(.caption)
                .foregroundStyle(Color.theme.secondaryText)
            Text(stat.value)
                .font(.headline)
                .foregroundStyle(Color.theme.accent)
            HStack(spacing: 4) {
                Image(systemName: "triangle.fill")
                    .font(.caption2)
                    .rotationEffect(Angle(degrees: stat.percentageChanged ?? 0 >= 0 ?
                            0 : 180))

                Text(stat.percentageChanged?.asPercentString() ?? "")
                    .font(.caption)
                    .bold()
            }
            .foregroundStyle(stat.percentageChanged ?? 0 >= 0 ? Color.theme.green : Color.theme.red)
            .opacity(stat.percentageChanged == nil ? 0 : 1)
        }
    }
}

#Preview {
    StatisticCoinView(stat: Preview.dev.stat3)
}
